function isNumber(value){
	if(!isNaN(value)){
		return true;
	}
	return false;
}

function round(value, length){
	if(isNaN(value)){
		alert("请输入一个有效的数值！");
		return;
	}
	if(length == undefined){
		length = 2;
	}
	return value.toFixed(length);
}

Namespace = new Object();
Namespace.register = function(fullNS)
{
    // 将命名空间切成N部分, 比如Grandsoft、GEA等
    var nsArray = fullNS.split('.');
    var sEval = "";
    var sNS = "";
    for (var i = 0; i < nsArray.length; i++)
    {
        if (i != 0) sNS += ".";
        sNS += nsArray[i];
        // 依次创建构造命名空间对象（假如不存在的话）的语句
        // 比如先创建Grandsoft，然后创建Grandsoft.GEA，依次下去
        sEval += "if (typeof(" + sNS + ")){ " + sNS + " = {};}";
    }
//    alert(sEval);
    if (sEval != ""){
    	eval(sEval);
    }
}

Namespace.register("com.gowholesale.admin");


com.gowholesale.admin.Product = function(){};

com.gowholesale.admin.Product.calculateCurrentPrice =function(originalPrice,discount,currentPriceId){
	if($.trim(originalPrice) != '' && $.trim(discount) != ''){
		if(!isNumber(originalPrice) || !isNumber(discount)){
			alert("原始价格或折扣必须为数字!");
			return ;
		}else{
			var currentPrice = round($.trim(originalPrice) * ($.trim(discount)/100));
			$("#" + currentPriceId).val(currentPrice);
		}
	}
}

com.gowholesale.admin.Product.calculateDiscount =function(originalPrice,currentPrice,discountId){
	if($.trim(originalPrice) != '' && $.trim(currentPrice) != ''){
		if(!isNumber(originalPrice) || !isNumber(currentPrice)){
			alert("原始价格或当前价格必须为数字!");
			return ;
		}else{
			var discount = round($.trim(currentPrice) / $.trim(originalPrice) * 100, 0);
			$("#" + discountId).val(discount);
		}
	}
}
